﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using HA.MT3DMS.DomainLayer;
namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winDefineSpecies.xaml 的交互逻辑
    /// </summary>
    public partial class winDefineSpecies : Window
    {
        public winDefineSpecies(List<MTSpecies> arrySpecies)
        {
            InitializeComponent();

            this._species = arrySpecies;

            this._ArrySpecies.Clear();
            foreach (MTSpecies arry in arrySpecies)
            {
                this._ArrySpecies.Add ((MTSpecies) arry.Clone ());
            }

            MenuItem itemCopy = new MenuItem();
            itemCopy.Header = "复制";
            itemCopy.Command = ApplicationCommands.Copy;

            //MenuItem itemPaste2 = new MenuItem();
            //itemPaste2.Header = "粘贴";
            //itemPaste2.InputGestureText = "Ctrl+V";
            //itemPaste2.Click += new RoutedEventHandler(itemPaste2_Click);

            ContextMenu cm = new ContextMenu();
            cm.Items.Add(itemCopy);
            //cm.Items.Add(itemPaste2);          
            this.dtGrid.ContextMenu = cm;
        }

        List<MTSpecies> _species;

        private List<MTSpecies> _ArrySpecies = new List<MTSpecies>();

        public List<MTSpecies> ArrySpecies
        {
            get { return _ArrySpecies; }
           
        }


        private MTGrid _grid = new MTGrid(1, 1, 1);

        public MTGrid Grid
        {
            get { return _grid; }
            set { _grid = value; }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.dtGrid.ItemsSource = ArrySpecies;
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            int i = this.dtGrid.Items.Count+1;
            this.ArrySpecies.Add(new MTSpecies("物种_"+i,true,Grid.Nrows,Grid.Ncols,Grid .Nlayers ));
            this.dtGrid.Items.Refresh();       
        }

        private void btnDel_Click(object sender, RoutedEventArgs e)
        {
            int Index = this.dtGrid .SelectedIndex;
            if (Index >= 0 && this.dtGrid.Items.Count > 0)
            {
                this.ArrySpecies.RemoveAt(Index);
                //this.DataContext = this.StressPeriod;
                this.dtGrid.Items.Refresh();
                if (Index >= this.dtGrid.Items.Count)
                {
                    Index = this.dtGrid.Items.Count - 1;
                }
                this.dtGrid.SelectedIndex = Index;
            }
        }
    }
}
